
module.exports=function($rootScope, $scope,$state,$timeout,financeCenterService,$cookies,caseSourcesService){
  //资金账户
  $scope.findUserAccountInfo=findUserAccountInfo;
  //获取收支记录
  $scope.findUserAccountDetailList=findUserAccountDetailList;
  //搜索
  $scope.financeCenterSearch=financeCenterSearch;
  //获取分类
  $scope.getFinanceCenterType=getFinanceCenterType;
  //提交 分类
  $scope.addFinanceCenterType=addFinanceCenterType;
  //开关
  $scope.finCeSelectOpen=finCeSelectOpen;
  //跳转
  $scope.finCenSkip=finCenSkip;
  //律师ID 用户ID
  $scope.FinLawyerId=kbt.decrypt($cookies.get('cookieUserId'));
  $scope.init=function(){
    $scope.pageSetting={
      pageNum:1,
      pageSize:10,
      serviceType:'',
      totalItems:''
    };
    $scope.findUserAccountInfo();
    $scope.findUserAccountDetailList();
    $scope.getFinanceCenterType();
  }
  $scope.init();
  $scope.finStatusType=[
    {code:1,name:'交易成功'},
    {code:2,name:'交易无效'},
    {code:93,name:'提现中'},
    {code:94,name:'提现成功'},
    {code:95,name:'提现失败'}
  ];
  $scope.finMoneyflowType=[
    {code:1,name:'收入'},
    {code:2,name:'支出'}
  ];

  function findUserAccountInfo(){
    financeCenterService.findUserAccountInfo($scope.FinLawyerId).then(function(data){
      if(data.code==1){
        if(data.data.length){
          $scope.accountInfo=data.data[0].balanceamount;
        }else{
          $scope.accountInfo=''
        }

      }
    })
  }

  function findUserAccountDetailList(){
    var params={
      beginNum:$scope.pageSetting.pageNum,
      pageSize:$scope.pageSetting.pageSize,
      serviceType:$scope.pageSetting.serviceType||'',
      beginTime:$scope.finDateNew||'',
      endTime:$scope.finDateOld||''
    }
    financeCenterService.findUserAccountDetailList(params).then(function(data){
      if(data.code==1){
        $scope.accountDetailList=data.data.list;
        $scope.pageSetting.totalItems=data.data.totalCount

      }
    })
  }
  function financeCenterSearch(){
    $scope.findUserAccountDetailList()
  }
  function getFinanceCenterType(){
    caseSourcesService.getServiceType().then(function(data){
      if(data.code==1){
        $scope.finClassifyList=data.data;
      }
    })
  }
  function addFinanceCenterType(id,name,event){
    $scope.finCeType=name;
    $scope.pageSetting.serviceType=id;
    $scope.finCeSelectToogle=false;
    $scope.findUserAccountDetailList();
    event.stopPropagation();

  }
  function finCeSelectOpen(event){
    $scope.finCeSelectToogle=true;
    event.stopPropagation();
  }

  function finCenSkip(id){
    $state.go('orderReceivingDetails',{id:id})
    sessionStorage.setItem('parentUrl',$state.current.name);
  }

  $("#financeCenter-details-new").datetimepicker({
    minView: "month",
    format: 'yyyy-mm-dd',
    language: "zh-CN",
    charset: "utf-8",
  }).on('changeDate', function (ev) {
    $('#financeCenter-details-new').datetimepicker('hide');
  });
  $("#financeCenter-details-old").datetimepicker({
    minView: "month",
    format: 'yyyy-mm-dd',
    language: "zh-CN",
    charset: "utf-8",
  }).on('changeDate', function (ev) {
    $('#financeCenter-details-old').datetimepicker('hide');
  });
  $('.y-team').on('click',function(){
    $scope.finCeSelectToogle=false;
  });


}
